package org.hairball;

import org.hairball.graph.HairballGraph;
import org.hairball.vis.DotGraphCreator;
import org.hairball.vis.GraphMarkupCreator;
import org.hairball.vis.GraphmlCreator;

import java.io.IOException;

public enum Format {
    DOT("dot", new DotGraphCreator()),
    GRAPHML("graphml", new GraphmlCreator());

    private String displayName;
    private GraphMarkupCreator markupCreator;

    Format(String displayName, GraphMarkupCreator hairballCreator) {
        this.displayName = displayName;
        this.markupCreator = hairballCreator;
    }

    public static Format getForDisplayName(String format) {
        if (format.equalsIgnoreCase("dot")) {
            return DOT;
        } else if (format.equalsIgnoreCase("graphml")) {
            return GRAPHML;
        } else {
            throw new UnsupportedOperationException(format + " not supported format");
        }
    }

    public String createDiagram(Configuration config) throws IOException {
        HairballGraphFactory hairballCreator = new HairballGraphFactory();
        HairballGraph hairballGraph = hairballCreator.create(config, config.getAnalysisTypes(), config.getJarFile());
        return markupCreator.createFromGraph("", hairballGraph);
    }

}
